package com.yc.cloud.admin.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import lombok.Data;

@Data
@Component
@ConfigurationProperties(prefix = "custom.mediakit")
public class MediaKitApiProperties {

	/** 协议，默认 http */
	private String scheme = "http";

	/** MediaKit服务IP或域名 */
	private String host;

	/** 端口，默认 6080 */
	private Integer port = 6080;

	/** API基础路径，默认 /index/api */
	private String apiBasePath = "/index/api";

	/** API鉴权secret */
	private String secret;

	/** 录制配置 */
	private RecordConfig record = new RecordConfig();
	
	/** 流配置 */
	private StreamConfig stream = new StreamConfig();

	/**
	 * 录制配置内部类
	 */
	@Data
	public static class RecordConfig {
		/** 应用名，默认 rtp */
		private String app = "rtp";
		
		/** 虚拟主机名，默认 __defaultVhost__ */
		private String vhost = "__defaultVhost__";
		
		/** 录制类型，默认 1 (hls录制) */
		private Integer type = 1;
		
		/** 自定义录制路径，默认 camera/ */
		private String customizedPath = "camera/";
	}
	
	/**
	 * 流配置内部类
	 */
	@Data
	public static class StreamConfig {
		/** RTMP端口 */
		private Integer rtmpPort = 1935;
		
		/** RTMP应用名 */
		private String rtmpApp = "rtp";
		
		/** FFmpeg流检查超时时间（秒） */
		private Integer checkTimeoutSeconds = 20;
		
		/** FFmpeg拉流重试次数 */
		private Integer pullRetryCount = 3;
		
		/**
		 * 构建RTMP流URL
		 * @param host MediaKit服务器地址
		 * @param streamId 流ID
		 * @return RTMP URL
		 */
		public String buildRtmpUrl(String host, String streamId) {
			return String.format("rtmp://%s:%d/%s/%s", host, rtmpPort, rtmpApp, streamId);
		}
	}

	/**
	 * 获取完整的基础URL
	 * @return 基础URL
	 */
	public String getBaseUrl() {
		return scheme + "://" + host + ":" + port + apiBasePath;
	}
}


